package team.lourd.network.system.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

/**
 * Create by Lourd on 2019/1/4
 */
@Configuration
public class MailConfig {


    /*
     spring.mail.test-connection=true
     spring.mail.host=smtp.gmail.com
     spring.mail.username=z1309014381@gmail.com
     spring.mail.password=zyd1362848650
     spring.mail.protocol=stmp
     spring.mail.properties.mail.smtp.auth=true
     spring.mail.properties.mail.smtp.starttls.enable=true
     spring.mail.default-encoding=UTF-8
     */
    @Bean
    public JavaMailSender getJavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.debug", "true");
        mailSender.setHost("smtp.gmail.com");
        mailSender.setPort(587);
        mailSender.setDefaultEncoding("UTF8");
        mailSender.setProtocol("smtp");
        mailSender.setUsername("z1309014381@gmail.com");
        mailSender.setPassword("zyd1362848650");
        mailSender.setJavaMailProperties(props);
        return mailSender;
    }

    @Bean
    public SimpleMailMessage templateSimpleMessage() {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setText(
                "This is the test email template for your email:\n%s\n");
        return message;
    }
}
